/**
 * Created by ajhin on 2/5/2015.
 */
package com.societyGames.socialFeedExercises
{
import com.societyGames.action.Action;

import flash.events.TimerEvent;
import flash.text.TextField;
import flash.utils.Timer;

public class ShowTextAction extends Action
{
  private var _textField:TextField;
  private var _text:String;
  private var _milliseconds:int;
  private var _timer:Timer;

  public function ShowTextAction(textField:TextField, text:String, milliseconds:int)
  {
    _textField = textField;
    _text = text;
    _milliseconds = milliseconds;
  }

  private function onTimerComplete(event:TimerEvent):void
  {
    _timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
    _timer = null;
    this._completeEventObject.dispatchEvent();
  }

  //IAction -->
  override public function startAction():void
  {
    this._textField.text = this._text;

    _timer = new Timer(_milliseconds, 1);
    _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete, false, 0, true);
    _timer.start();
  }
  //<--IAction
}
}
